
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Browser;

namespace SignatureDraw
{

    public partial class Page : UserControl
    {
        private SignatureDrawing _signatureDrawing;
		private sigs sigs = new sigs();
        public Page()
        {
            InitializeComponent();
			
			this.Width= sigs.wh;
			this.Height= sigs.ht;
			this.spControl.Height = 20; 
			
			//sigs.sig = sig;

            _signatureDrawing = new SignatureDrawing(sigs);
			
            LayoutRoot.Children.Add(_signatureDrawing);

            KeyDown += new KeyEventHandler(Page_KeyDown);
			
			Loaded += new RoutedEventHandler(Page_Loaded);
			
			
        }
		
		
		public void Page_Loaded(object o, EventArgs e)  
    	    {  
			double s = sigs.scale;
			//this.sigs.alert(s.ToString());
			this._signatureDrawing.gobig(s);
			double h = sigs.ht;
	        double w = sigs.wh;
			this.Height = h;
			this.Width = w;
			//adjust 
			if (s < 1) {
			this.Height = 0;
			this.Width = 0;
			}
		}	
//        void Page_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
//        {
//            // hide the cover
//            //LayoutRoot.Children.Remove(Cover);
//            _simpleDrawing = new SimpleDrawing("default");
//            LayoutRoot.Children.Add(_simpleDrawing);      
//        }


		private void btnRedraw_Click( object sender, RoutedEventArgs e )
        {
    	        this.tblText.Text = "";//"Redrawing";
			_signatureDrawing.redraw();
        }

		private void btnClear_Click( object sender, RoutedEventArgs e )
        {
    	        this.tblText.Text = "";//"Clearing Drawing";
			_signatureDrawing.clearScreen();
			_signatureDrawing.clearData();
			
        }

		private void btnSaveSig_Click( object sender, RoutedEventArgs e )
        {
    	        this.tblText.Text = "";//"Saving Signature";
			//_simpleDrawing.saveSig();
			sigs.sig = _signatureDrawing.getNewSig();
			this.sigs.savesig();    //alert(_signatureDrawing.getNewSig());
        }

		private void btnShow_Click( object sender, RoutedEventArgs e )
        {
    	        this.tblText.Text = "";//"Showing Signature";
			_signatureDrawing.getSig();
			_signatureDrawing.redraw();
			
        }

		
        void Page_KeyDown(object sender, KeyEventArgs e)
        {

            if (e.Key == Key.R)
            {
                if (_signatureDrawing != null)
                {
                    _signatureDrawing.redraw();
                }
            }
			if (e.Key == Key.C)
            {
                if (_signatureDrawing != null)
                {
                    _signatureDrawing.clearScreen();
                }

				//this.sigs.alert("all clear");
            }
			if (e.Key == Key.T)
            {
                if (_signatureDrawing != null)
                {
			        //this.sigs.alert(sigs.ht.ToString());
					this._signatureDrawing.gobig(double.Parse("1.25"));
					double h = sigs.ht;
	                double w = sigs.wh;
					this.Height = h; 
					this.Width = w;

                }

			}
			if (e.Key == Key.V)
            {
                if (_signatureDrawing != null)
                {
					this._signatureDrawing.gosmall(double.Parse(".75"));
					double h = sigs.ht;
	                double w = sigs.wh;
					this.Height = h; 
					this.Width = w;					
                }

			}
			
			if (e.Key == Key.S)
            {
				
				if (_signatureDrawing != null)
                {
					//show panel
			        _signatureDrawing.set400();
				
                }

			}
			if (e.Key == Key.H)
            {
                if (_signatureDrawing != null)
                {
					//hide panel
			        _signatureDrawing.set500();
                }

			}
			
        }
    }
}
